local sk__taoxi = fk.CreateSkill {

  name = "sk__taoxi",

  tags = {  },

}



sk__taoxi:addEffect("active", {
  name = "sk__taoxi",
  anim_type = "control",
  card_num = 0,
  target_num = 0,
  prompt = "#sk__taoxi",
  can_use = function(self, player)
    return player:usedSkillTimes(sk__taoxi.name, Player.HistoryPhase) == 0 and
      table.find(Fk:currentRoom().alive_players, function(p) return p ~= player and not p:isKongcheng() end)
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local targets = room:getOtherPlayers(player)
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    local mark = player:getTableMark("sk__taoxi-phase")
    for _, target in ipairs(targets) do
      if player.dead then return end
      if not target.dead and not target:isKongcheng() then
        local card = room:askForCardChosen(player, target, "h", sk__taoxi.name, "#sk__taoxi-card::"..target.id)
        table.insert(mark, {target.id, card})
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, sk__taoxi.name, nil, false, player,
          {"@sk__taoxi-phase", Fk:translate(target.general)})
      end
    end
    if not player.dead then
      room:setPlayerMark(player, "sk__taoxi-phase", mark)
    end
  end,
})

sk__taoxi:addEffect(fk.EventPhaseEnd, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:usedSkillTimes("sk__taoxi", Player.HistoryPhase) > 0 then
      local mark = player:getTableMark("sk__taoxi-phase")
      for _, info in ipairs(mark) do
        local to = player.room:getPlayerById(info[1])
        if not to.dead and table.contains(player:getCardIds("h"), info[2]) then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("sk__taoxi-phase")
    for _, info in ipairs(mark) do
      if player.dead then return end
      local to = room:getPlayerById(info[1])
      if not to.dead and table.contains(player:getCardIds("h"), info[2]) then
        room:moveCardTo(info[2], Card.PlayerHand, to, fk.ReasonGive, "sk__taoxi", nil, false, player)
      end
    end
  end,
})

return sk__taoxi